<!--头部公共部分-->
{include file="common/header" /}
<div style="padding:15px;">
    <form class="layui-form layui-form-pane">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>物品名称</label>
                <div class="layui-input-inline">
                    <input type="text" name="goods_name"  lay-verify="required" autocomplete="off" placeholder="请输物品名称" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>库存数量</label>
                <div class="layui-input-inline">
                    <input type="number" min="0"  name="put_nums"   lay-verify="required" autocomplete="off" value="0" placeholder="请输库存数量" class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>成本单价</label>
                <div class="layui-input-inline">
                    <input type="number" min="0" name="cost_price"  lay-verify="required" autocomplete="off" value="0" placeholder="请输物品单价" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>单价</label>
                <div class="layui-input-inline">
                    <input type="number" min="0" name="price"  lay-verify="required" autocomplete="off" value="0"  placeholder="请输物品单价" class="layui-input">
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>单位</label>
                <div class="layui-input-inline">
                    <input type="text" name="unit"  lay-verify="required" autocomplete="off" placeholder="请输物品单位" class="layui-input">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>校区</label>
                <div class="layui-input-inline">
                    <select name="campus_id"  lay-verify="required" lay-search="">
                        <option value="">请选择校区</option>
                        {foreach name="campus" id="v"}
                        <option value="{$v.id}">{$v.campus_name}</option>
                        {/foreach}
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label"><span class="x-red">*</span>类型</label>
                <div class="layui-input-inline">
                    <select name="type"  lay-verify="required" lay-search="">
                        <option value="">请选择类型</option>
                        <option value="0">物品类</option>
                        <option value="1">杂费类</option>
                    </select>
                </div>
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <input class="layui-btn" lay-submit lay-filter="form" value="立即提交" readonly>
            </div>
        </div>
    </form>
</div>
<!--底部公共部分-->
{include file="common/footer" /}

<script>
    layui.use(['element', 'jquery','form','layer'], function(){
        var $ = layui.jquery
            ,element = layui.element
            ,layer = layui.layer
            ,form = layui.form;

        //监听提交
        form.on('submit(form)', function (data) {
            var field = data.field;
            field.company_id = "{$company_id}";
            var isLoad;
            $.ajax({
                url: '/admin/goods/goods_add',
                method: "post",
                data: field,
                beforeSend: function () {
                    isLoad = layer.load(0, {
                        shade: false
                    }); //0代表加载的风格，支持0-2
                },
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.code === 1) {
                        setTimeout(function () {
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layer.close(index); //再执行关闭
                            parent.location.reload();
                        }, 2000);
                    }
                },
                complete: function () {
                    layer.close(isLoad)
                },
                error: function (error) {
                    console.log(error)
                }
            });
            return false;
        });
    });

</script>